home *** CD-ROM | disk | FTP | other *** search
- Path: news.unt.edu!news
- From: Steve Fogoros <sfogoros@hsc.unt.edu>
- Newsgroups: comp.lang.c
- Subject: Re: Data Name to Pointer Question
- Date: Wed, 06 Mar 1996 23:18:35 -0800
- Organization: University of North Texas Health Science Center
- Message-ID: <313E8DCB.922@hsc.unt.edu>
- References: <4hkhtb$epm@theopolis.orl.mmc.com>
- NNTP-Posting-Host: sfogoros.hsc.unt.edu
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (Win16; I)
-
- Steve Woodcock wrote:
- >
- > Hello All:
- >
- > Apologies in advance is this is so mind-bogglingly simple that I'm
- > somehow missing it.
- >
- > I have a data file containg the name of a structure called
- > "process one", as such
- >
- > #
- > # comments
- > #
- > process_one
- > #
- > # comments
- >
- > Over in the program itself, "process one" is a data structure filled
- > with information.
- >
- > Is there a way for me to convert the string "process one" that I read
- > in from the data file to a pointer pointing to the actual structure
- > "process one"? Essentially, I want to turn the contents of this string
- > variable into the *name* of the variable I want to access.
- >
-
- I saw an inplementation similar to what you describe, in a ProCom unix port written by a man at Fort Hood
- in Kilene, Texas. He stored function names and pointers for the program's menus. At run time you selected
- a function from the menu. This made it easier to maintain the menu lists because they were all in one
- place. A small dispatch function would display the menu and accept selection. He also switched menu lists
- based on user selection. (If anybody knows offhand where I can get it again? I had to leave it at a
- company that I had to leave.)
-
- The basic idea is to create a structure (slst) to hold the text name of a data structure and pointer to
- it. You have to do this in the source because you will loose the declared name when you compile. Declare a
- static array of slst and initialize it with the data structure names and pointers in your program that you
- expect to find in the file. As you acquire a name out of file, strcmp() it against the names in slst[]. If
- you match the name, you will then have a pointer to the actual structure.
-
- I have a question for you. Do your data structures all have the same names and types for members? Once you
- have a pointer to a data structure, how will you access member elements? If they are all the same you
- should have no problem. You can hardwire the member names. If your structures have different names and
- types for members, I'm not sure how to access a member element. (Maybe char by char?)
-
- I would like to know more about the specific nature of your data structures because you may need to
- re-think the relationship between your data structures and your driver file. (Since I'm in the dark here,
- you may also be right on track.)
-
- --
- Steve Fogoros, Academic Information Coordinator
- University of North Texas Health Science Center
- sfogoros@hsc.unt.edu
-